package cn.gmph.blog.admin.service.sys.dao;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.annotations.UpdateProvider;

import cn.gmph.blog.admin.service.sys.dao.helper.UsermetaProvider;
import cn.gmph.blog.admin.service.sys.entity.UsermetaDO;

import java.util.List;;

public interface UsermetaDAO {

    @Results({@Result( column = "umeta_id",property = "umetaId"),@Result( column = "user_id",property = "userId"),@Result( column = "meta_key",property = "metaKey"),@Result( column = "meta_value",property = "metaValue") })
    @Select("SELECT * FROM wp_usermeta WHERE id = #{id}")
    public UsermetaDO getById(@Param("id") int id);

    @Insert("INSERT into wp_usermeta(umeta_id,user_id,meta_key,meta_value) VALUES (#{umetaId},#{userId},#{metaKey},#{metaValue})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    public void insert(UsermetaDO usermeta);

    @Delete("DELETE FROM wp_usermeta WHERE id = #{id}")
    public int deleteById(@Param("id") int id);

    @UpdateProvider(type = UsermetaProvider.class, method = "update")
    public int update(@Param("usermeta") UsermetaDO  usermeta);

    @Results({@Result( column = "umeta_id",property = "umetaId"),@Result( column = "user_id",property = "userId"),@Result( column = "meta_key",property = "metaKey"),@Result( column = "meta_value",property = "metaValue") })
    @SelectProvider(type = UsermetaProvider.class, method = "pageList")
    public List<UsermetaDO> pageList(@Param("usermeta") UsermetaDO usermeta, @Param("pageNum") Integer pageNum, @Param("pageSize") Integer pageSize);

    @SelectProvider(type = UsermetaProvider.class, method = "pageListCount")
    public Integer pageListCount(@Param("usermeta") UsermetaDO usermeta);

}